import Vue from "vue";
import VueRouter from "vue-router";
Vue.use(VueRouter);
import Home from "./components/HelloWorld.vue";
const router = new VueRouter({
  routes: [
    {
      path: "/",
      redirect: "home",
      meta: { title: "首页" },
    },
    {
      path: "/home",
      component: Home,
      name: "home",
      meta: { title: "首页" },
    },
  ],
});
// to,是将要跳转的路由
// from，是离开的路由
// next是个方法，判断to.path 或者 from.path ,如果符合条件，则允许跳转
router.beforeEach((to, from, next) => {
  if (to.meta.title) {
    document.title = to.meta.title;
  }
  next();
});
export default router;
